package com.example.cdctestsystem.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieUtil {
    public static void addCookie(String name, String value, String path, int maxAge, HttpServletResponse response){
        Cookie cookie=new Cookie(name,value);
        cookie.setMaxAge(maxAge);
        cookie.setPath(path);
        response.addCookie(cookie);
    }
    public static  String getValue(String name, HttpServletRequest request){
        String value=null;
        Cookie[] cookies=request.getCookies();
        if(cookies!=null){
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(name)){
                    value=cookie.getValue();
                    break;
                }
            }
        }
        return value;
    }
}
